package com.yk.neon.lib.util.mybatis.repository;





import com.yk.neon.lib.util.mybatis.dao.MybatisBaseMapper;
import com.yk.neon.lib.util.mybatis.entity.Persistable;

import java.io.Serializable;

public abstract class AbstractCrudRepository<T extends Persistable, ID extends Serializable, Example>
		implements CrudRepository<T, ID> {

	protected abstract MybatisBaseMapper<T, ID, Example> getBaseMapper();

	@Override
	public <S extends T> S insert(S entity) {
		getBaseMapper().insert(entity);
		return entity;
	}

	@Override
	public <S extends T> S insertSelective(S entity) {
		getBaseMapper().insertSelective(entity);
		return entity;
	}

	@Override
	public <S extends T> S update(S entity) {
		getBaseMapper().updateByPrimaryKey(entity);
		return entity;
	}

	@Override
	public <S extends T> S updateByPrimaryKeySelective(S entity) {
		getBaseMapper().updateByPrimaryKeySelective(entity);
		return entity;
	}

	@Override
	public T findOne(ID id) {
		return getBaseMapper().selectByPrimaryKey(id);
	}

	@Override
	public boolean exists(ID id) {
		return findOne(id) != null;
	}
}
